package com.iplay.component.excel.core;

import java.lang.reflect.Field;

import com.iplay.component.excel.annotation.Column;

public class ColumnMetaData {
	private int columnIndex = -1;
	private String columnName;
	private Field field;
	@SuppressWarnings("rawtypes")
	private Converter converter;

	public ColumnMetaData(Field field) {
		this.field = field;
		columnName = field.getName();
		if (field.isAnnotationPresent(Column.class)) {
			Column columnAnno = field.getAnnotation(Column.class);
			if (!"".equals(columnAnno.value())) {
				columnName = columnAnno.value();
			}
			if (columnAnno.convert() != Converter.class) {
				try {
					converter = columnAnno.convert().newInstance();
				} catch (InstantiationException | IllegalAccessException e) {
					e.printStackTrace();
				}
			}
		}
	}

	public int getColumnIndex() {
		return columnIndex;
	}

	public String getColumnName() {
		return columnName;
	}

	@SuppressWarnings("rawtypes")
	public Converter getConverter() {
		return converter;
	}

	public void setColumnIndex(int columnIndex) {
		this.columnIndex = columnIndex;
	}

	public Field getField() {
		return field;
	}
}
